home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10576 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: galaxy.ucr.edu!not-for-mail
  2. From: thp@cs.ucr.edu (Tom Payne)
  3. Newsgroups: comp.programming.threads,comp.lang.c++,comp.unix.osf.osf1,comp.unix.programmer,comp.object
  4. Subject: Re: Looking for best design for using pthreads in C++ objects
  5. Followup-To: comp.programming.threads,comp.lang.c++,comp.unix.osf.osf1,comp.unix.programmer,comp.object
  6. Date: 8 Mar 1996 18:39:04 GMT
  7. Organization: University of California, Riverside
  8. Message-ID: <4hpus8$ld6@galaxy.ucr.edu>
  9. References: <3128ff8b.666031216@news.clark.net> <312A0E5F.7B2C@ix.netcom.com> <31320705.41C6@zko.dec.com>
  10. NNTP-Posting-Host: corvette.ucr.edu
  11. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  12.  
  13. Webb Scales (scales@zko.dec.com) wrote:
  14. : David Brownell wrote:
  15. : > One of the really nice techniques is to have a "Locker" class to grab mutexes
  16. : > as needed, and then release it automatically on all exits.  [...]
  17. : > That kind of class really helps get rid of the bugs you have due
  18. : > to locks not getting released uniformly on all codepaths.
  19. : For instance, if a thread holding a mutex via the "Locker" class terminates
  20. : prematurely (due to an exception or cancellation), then the mutex will be
  21. : unlocked automagically, despite the fact that whatever it was supposed to
  22. : protect is now likely to be in an inconsistent state.  
  23.  
  24. Good point.  In my use of Lockers, I always pass a pointer to the surrounding
  25. (monitor) object so that the Locker can find and acquire the local lock, e.g.,
  26.  
  27.      Locker exclusion(this);
  28.  
  29. Thus, the Locker's destructor can assert the monitor's invariants or
  30. check them and attempt to tidy up.  What I'd really like is a way for
  31. my destructor to know that it is being called through the processing
  32. of an exception and to have access to that exception object.
  33.  
  34. Tom Payne (thp@cs.ucr.edu)
  35.